package com.game.Maze.Util;

import java.util.Random;

/**
 * Перечислимый тип сторон света
 * 
 */
public enum WorldSide
{
  None, NorthWest, North, NorthEast, East, SouthEast, South, SouthWest, West;

  /**
   * @param side заданная сторона света 
   * @return сторону света противоположную заданной
   */
  public static WorldSide oppositeSide(WorldSide side)
  {
    switch (side)
    {
      case NorthWest:
        return SouthEast;

      case North:
        return South;

      case NorthEast:
        return SouthWest;

      case East:
        return West;

      case SouthEast:
        return NorthWest;

      case South:
        return North;

      case SouthWest:
        return NorthEast;

      case West:
        return East;
    }
    
    return side;
  }
  
  /**
   * Возвращает случайно выбранную сторону света.
   * @return случайная сторона света
   */
  public static WorldSide randomSide()
  {
    Random greatRandom = new Random();
    WorldSide newSide = None;
    
    while (None == newSide)
      newSide = WorldSide.values()[greatRandom.nextInt(WorldSide.values().length)];
    
    return newSide;
  }
  
  /**
   * Возвращает случайно выбранную основную сторону света (С, Ю, В, З)
   * @return случайная основная сторона света
   */
  public static WorldSide randomMainSide()
  {
    WorldSide newSide = randomSide();
    
    while (NorthEast == newSide || NorthWest == newSide || SouthEast == newSide || SouthWest == newSide)
      newSide = randomSide();
      
    return newSide;
  }
}
